StaffForm = Ext.extend(Ext.Window, {
	formPanel : null,
	constructor : function(a) {
		Ext.applyIf(this, a);
		this.initUIComponents();
		StaffForm.superclass.constructor.call(this, {
			layout : "fit",
			id : "StaffFormWin",
			iconCls : "menu-dictionary",
			items : this.formPanel,
			title : "员工信息",
			width : 550,
			height : 400,
			modal : true,
			buttonAlign : "center",
			buttons : this.buttons
		});
	},
	initUIComponents : function() {
		
		this.formPanel = new Ext.FormPanel({
			url : __ctxPath + "/system/saveStaff.do",
			layout : "form",
			id : "StaffForm",
			bodyStyle : "padding:5px",
			border : false,
			formId : "StaffFormId",
//			defaultType : "textfield",
			defaults : {
				anchor : "98%,98%"
			},
			items : {
				xtype : "panel",
				border : false,
				layout : "hbox",
				layoutConfig : {
					padding : "5",
					align : "middle"
				},
				defaults : {
					style : "padding:0px 5px 0px 5px;",
					anchor : "98%,98%",
					height : 280,
					width : "38%"
				},
				items : [
						{
							xtype : "panel",
							title : "必填信息",
							labelWidth : 81,
							height : 280,
							width : 250,
							defaults : {
								anchor : "98%,98%"
							},
							bodyStyle : "padding:5px;",
							layout : "form",
							defaultType : "textfield",
							labelAlign : "right",
							hideLabels : false,
							items : [
									{
										xtype : "hidden",
										fieldLabel : "员工ID",
										name : "staff.id"
									},
									{
										fieldLabel : "工号",
										name : "staff.cardNo",
										allowBlank : false,
										blankText : "工号不能为空!"
									},
									{
										fieldLabel : "姓名",
										name : "staff.name",
										allowBlank : false,
										blankText : "姓名不能为空!"
									},
									{
										fieldLabel : "入职时间",
										xtype : "datefield",
										format : "Y-m-d",
										name : "staff.accessionTime",
										allowBlank : false,
										blankText : "入职时间不能为空!",
										length : 50
									},
									/*{
										xtype : "hidden",
										name : "staff.department.depId",
										id : "staff.department.depId"//此处的id TreeSelector 会用到
									},new TreeSelector(
											"staff.department.depName",
											__ctxPath + "/system/getAllDepartment.do",
											'部门',
											"staff.department.depId",
									false),*/
									{
										fieldLabel : "状态",
										hiddenName : "staff.status",
										xtype : "combo",
										mode : "local",
										editable : false,
										triggerAction : "all",
										store : [
												[ "1", "激活" ],
												[ "0", "禁用" ] ],
										value : 1
									},
									
									 ]
						},
						{
							xtype : "panel",
							title : "选填信息",
							layout : "form",
							defaultType : "textfield",
							labelWidth : 81,
							height : 280,
							width : 250,
							defaults : {
								anchor : "98%,98%"
							},
							hideLabel : false,
							bodyStyle : "padding:5px;",
							labelAlign : "right",
							items : [ 
									{
										fieldLabel : "性别",
										xtype : "combo",
										hiddenName : "staff.title",
										name : "staff.title",
										mode : "local",
										editable : false,
										triggerAction : "all",
										store : [
													[ "1", "先生" ],
													[ "0", "女士" ] 
												],
										value : "1"
									},
									{
										fieldLabel : "联系电话",
										name : "staff.phone"
									},
									{
										fieldLabel : "手机号码",
										xtype : "numberfield",
										name : "staff.mobile"
									},
									{
										fieldLabel : "家庭住址",
										name : "staff.address"
									},
									{
										fieldLabel : "受教育程度",
										name : "staff.education"
									},
									{
										fieldLabel : "E-mail",
										name : "staff.email",
										vtype : "email",
										blankText : "邮箱不能为空!",
										vtypeText : "邮箱格式不正确!"
									},
									{
										fieldLabel : "传真",
										name : "staff.fax"
									},
									]
						} ]
			}
		});
		Ext.getCmp("StaffForm").getForm().reset();
		if (this.staffId != null && this.staffId != "undefined") {
			this.formPanel.loadData({
				url : __ctxPath + "/system/getStaff.do?staff.id="+ this.staffId,
				preName : "staff",
				root : "result",
				success : function(form, action) {
					var obj = Ext.decode(form.responseText).result;
					var StaffForm  = Ext.getCmp("StaffForm").getForm();
					//设置入职时间
					StaffForm.findField("staff.accessionTime").setValue(new Date(obj.accessionTime));
					//设置性别
					StaffForm.findField("staff.title").setValue(obj.title);
					//设置状态
					StaffForm.findField("staff.status").setValue(obj.status);
					
//					StaffForm.findField("staff.department.depId").setValue(obj.department.depId);
//					StaffForm.findField("staff.department.depName").setValue(obj.department.depName);
				} 
			
			});
		}
		this.buttons = [ {
			text : "保存",
			iconCls : "btn-save",
			handler : this.save.createCallback(this.formPanel, this)
		}, {
			text : "重置",
			iconCls : "btn-reset",
			handler : this.reset.createCallback(this.formPanel)
		}, {
			text : "取消",
			iconCls : "btn-cancel",
			handler : this.cancel.createCallback(this)
		} ];
	},
	reset : function(a) {
		a.getForm().reset();
	},
	cancel : function(a) {
		a.close();
	},
	save : function(a, b) {
		var c = b.callback;
		if (a.getForm().isValid()) {
			a.getForm().submit({
				method : "POST",
				waitMsg : "正在提交数据...",
				success : function(d, e) {
					Ext.ux.Toast.msg("操作信息", "成功保存信息！");
					if (b.callback) {
						b.callback.call(this);
					}
					Ext.getCmp("StaffGrid").getStore().reload();
					b.close();
				},
				failure : function(d, e) {
					var result = e.result;
					Ext.MessageBox.show({
						title : "操作信息",
						msg : result.msg == null ? "信息保存出错，请联系管理员！" : result.msg,
						buttons : Ext.MessageBox.OK,
						icon : Ext.MessageBox.ERROR
					});
					b.close();
				}
			});
		}
	}
});